﻿using System;
using System.Web;
using System.Collections.Generic;

namespace TQB.Demo.WebIM.WebApp
{
    public class MyHandler : IHttpHandler
    {
        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            //write your handler implementation here.

            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            List<MyAsyncResult> userlist = MyAsyncHandler.Queue;
            string sessionId = context.Request.QueryString["sessionId"];
            string message = context.Request.QueryString["message"];

            foreach (MyAsyncResult res in userlist)
            {
                //如果不是自己就推
                if (res.SessionId != sessionId)
                {
                    //激发callback，结束请求      
                    res.Message = message;
                    res.SetCompleted(true);
                }
            }
        }

        #endregion
    }
}
